#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int num = nums[0];
        int times = 0;
        for (auto e : nums)
        {
            if (times == 0)
                num = e;
            times += (e == num) ? 1 : -1;
        }
        int count = 0;
        for (auto e : nums)
            if (e == num)
                count++;
        return count > nums.size() / 2 ? num : -1;
    }
};